#include <bits/stdc++.h>
//#define int long long
using namespace std;
const int N=1e5+5;
int T,n,m,l,V,d[N],v[N],a[N];

int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);

    cin>>T;
    while(T--)
    {
        int ans=0;
        cin>>n>>m>>l>>V;
        for(int i=1;i<=n;i++)
        {
            cin>>d[i]>>v[i]>>a[i];
        }
        int p;
        for(int i=1;i<=m;i++)
            cin>>p;
        for(int i=1;i<=n;i++)
        {
            if(d[i]<=p&&v[i]>V) ans++;
        }
        if(ans!=0)
            cout<<ans<<" "<<m-1<<endl;
        else
            cout<<ans<<" "<<m<<endl;
    }

    fclose(stdin);
    fclose(stdout);
    return 0;
}
